/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package midpmpc.ui;

import javax.microedition.lcdui.Graphics;
import org.j4me.ui.Theme;
import org.j4me.ui.components.Component;

/**
 *
 * @author vvs
 */
public class Progressbar extends Component{

    int val=0,max=1;
    String _title;
    public Progressbar(String title)
    {
        _title=title;
    }
    public void setVal(int value,int maxValue)
    {
        val=value;
        max=maxValue;
        repaint();
    }
    public boolean acceptsInput()
    {
        return true;
    }
    public int[] getVal()
    {
        return new int[]{val,max};
    }
    protected int[] getPreferredComponentSize (Theme theme, int viewportWidth, int viewportHeight)
    {
        int height=theme.getFont().getHeight()*2;
        return new int[] {viewportWidth,height};
    }
    protected void paintComponent (Graphics g, Theme theme, int width, int height, boolean selected)
    {
        int backgroundColor = selected ?
                        theme.getHighlightColor() :
                        theme.getBackgroundColor();
        g.setColor( backgroundColor );
        g.fillRect( 0, 0, width, height );
        int fontColor = selected ?
                theme.getBackgroundColor() :
                theme.getFontColor();
        g.setFont(theme.getFont());
        g.setColor(fontColor);
        g.drawString(_title+": "+val+"/"+max, 0,0,Graphics.LEFT|Graphics.TOP);
        g.setColor(0,0,0);
        width-=1;
        g.drawRect(0, height/2, width, height/2);
        int pw=val*(width-1)/max;
        g.setColor(fontColor);
        g.fillRect(1, height/2+1, pw, height/2-1);


    }
}
